//
//  YHObject.m
//  YHObject
//
//  Created by Guanglu on 18/3/2019.
//

#import "YYModel.h"
#import "SHObject.h"

@implementation NSObject (SHNSObject)
+ (instancetype)objectFromJson:(id)json
{
    return [self yy_modelWithJSON:json];
}

+ (instancetype)objectFromDict:(NSDictionary *)dictionary
{
    return [self yy_modelWithDictionary:dictionary];
}

- (id)jsonObject
{
    return self.yy_modelToJSONObject;
}

- (NSData *)jsonData
{
    return self.yy_modelToJSONData;
}

- (NSString *)jsonString
{
    return self.yy_modelToJSONString;
}

- (instancetype)sh_initWithCoder:(NSCoder *)aDecoder
{
    return [self yy_modelInitWithCoder:aDecoder];
}

- (void)sh_encodeWithCoder:(NSCoder *)coder
{
    [self yy_modelEncodeWithCoder:coder];
}

//- (NSString *)debugDescription
//{
//    return [NSString stringWithFormat:@"%@ %p : %@", NSStringFromClass(self.class), self, self.yy_modelToJSONString];
//}

@end

#pragma mark -

@implementation SHObject

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];
    return [self sh_initWithCoder:aDecoder];
}

- (void)encodeWithCoder:(NSCoder *)coder
{
    [self sh_encodeWithCoder:coder];
}

@end


#pragma mark -
@implementation NSArray (SHNSObject)
+ (NSArray *)modelArrayWithClass:(Class)cls json:(id)json
{
    return [self yy_modelArrayWithClass:cls json:json];
}
@end

@implementation NSDictionary (ASHNSObject)

+ (NSDictionary *)modelDictionaryWithClass:(Class)cls json:(id)json
{
    return [self yy_modelDictionaryWithClass:cls json:json];
}

@end
